<?php

/**
 * Settings - Profile
 * 
 * @project : Loobica
 * @author  : Dino
 * @date    : 27 Mar 2014
 * 
 */
if (!defined('BASEPATH'))
  exit('No direct script access allowed');

class Profile extends LB_Auth_Controller {

  /**
   * Current User Profile Edit
   * 
   */
  public function index() {

    $status = false;
    $user_types = array(1, 2, 3, 4);

    // Submit
    if ($this->is_post()) {

      // Getting inputs
      $user_type = (int) $this->input->post('user_type', true);
      $user_display_name = (string) $this->input->post('user_display_name', true);
      $user_locality = (string) $this->input->post('user_locality', true);
      $user_phone_number = (int) $this->input->post('user_phone_number', true);
      $user_mobile_number = (int) $this->input->post('user_mobile_number', true);
      $user_address = (string) $this->input->post('user_address', true);

      // Cleaning inputs
      $user_update = array();
      $user_update['user_type'] = (in_array($user_type, $user_types)) ? $user_type : 1;
      $user_update['user_display_name'] = namefy_text($user_display_name);
      $user_update['user_locality'] = namefy_text($user_locality);
      $user_update['user_phone_number'] = numerify_text($user_phone_number);
      $user_update['user_mobile_number'] = numerify_text($user_mobile_number);
      $user_update['user_address'] = sanitize(substr($user_address, 0, 500));

      // Updating user details
      $status = $this->user_model->set_user($user_update, $this->signed_user['user_id']);
    }

    // Getting user data
    $user_data = $this->user_model->get_user_id($this->signed_user['user_id'], 1, true);

    // Getting user location
    $user_location = $this->user_location->get_key_data($this->signed_user['user_location_key']);

    // Preparing view data
    $view_data = array();
    $view_data['title'] = 'Settings - Profile';
    $view_data['status'] = $status;
    $view_data['user_data'] = $user_data;
    $view_data['user_location'] = $user_location;

    // Loading view
    $this->load_view('settings/profile', $view_data);
    return;
  }

}

?>